package cn.tedu._07springaop.egaop1;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class OrderCheckAspect {
    @Before(value = "execution(public void cn.tedu._07springaop.egaop1.OrderServiceImpl.*(..))")//注意返回值类型
    public void before(JoinPoint joinPoint) {
        int number = (int)joinPoint.getArgs()[0];
        if (number <= 0){
            throw new IllegalArgumentException("订单号必须大于0");
        }
        System.out.println("检查订单完毕");
    }
    @AfterReturning(value = "execution(public void cn.tedu._07springaop.egaop1.OrderServiceImpl.*(..))", returning = "result")//注意返回值类型
    public void afterReturning(JoinPoint joinPoint, Object result) {
        String name = joinPoint.getSignature().getName();
        System.out.println("订单处理完毕" + name + result);
    }
}
